// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class COMPONENTS_RAS_O01 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("42 RXC",42)]
  	    [HL7Field(HL7Version.v23, 42, HL7Repeat.True, HL7Required.True,"RXC")]
	    public RXC[] RXC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("46 NTE",46)]
  	    [HL7Field(HL7Version.v23, 46, HL7Repeat.True, HL7Required.False,"NTE")]
	    public NTE[] NTE {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			RXC = PopSegmentParseAndCheckRequiredArray<RXC>(availableData, options, "RXC");
			NTE = PopSegmentParseAndCheckRequiredArray<NTE>(availableData, options, "NTE");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isRXC = availableData.StartsWith("RXC", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("RXC", options.Version) || isRXC) {
				return isRXC;
			}
			bool isNTE = availableData.StartsWith("NTE", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("NTE", options.Version) || isNTE) {
				return isNTE;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "COMPONENTS";
			}
        }

        static COMPONENTS_RAS_O01() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(COMPONENTS_RAS_O01));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (RXC != null && RXC.Length > 0) {
			for (int i = 0; i < RXC.Length; i++) {
				string segmentValue = RXC[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
		 if (NTE != null && NTE.Length > 0) {
			for (int i = 0; i < NTE.Length; i++) {
				string segmentValue = NTE[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

